<?php
	
	include_once '../controladores/ControladorElementos.php';
	include_once '../controladores/ControladorSecciones.php';
	include_once '../config.inc.php';
	include_once '../clases/menu_element.php';
	
		$usr = $_GET['usr'];
		$app = $_GET['app'];
		$secc = $_GET['sec'];
	
	$command = new ControladorElementos(MENU_LIST);
	
	$orderNewElement = $command->obtainOrderNewElement($app,$secc) + 1;		
	
	$command->createElement(array("sec_id" => $secc,"element_order" => $orderNewElement));
		
	$menuListId = $command->obtainIdMenuList($app,$secc);
	
		$options = $_POST['optionName'];
		$actions = $_POST['actionOptions'];
		$sections = $_POST['sectionsPath'];
				
	$dynamicIndex = null;
	$elements = array();
	
		for ($i=0; $i < count($actions); $i++)
		  if ($actions[$i] == "1")	
			$elements[$i] = new MenuElement($secc,$menuListId,($i+1),$options[$i],$sections[$i]);
		  else
			$elements[$i] = new MenuElement($secc,$menuListId,($i+1),$options[$i],"");
					
	$command = new ControladorElementos(MENU_ELEMENT);
	
	 	for ($j=0; $j < count($elements); $j++)
			$command->createElement(array("sec_id" => $elements[$j]->getSecId(), "men_element_id" => $elements[$j]->getMenuElementId(), "element_order" => $elements[$j]->getElementOrder(), "me_content" => $elements[$j]->getContent(), "me_link_to" => $elements[$j]->getLinkTo()));
			
		header("Location:section_elements.php?usr=".$usr."&app=".$app."&sec=".$secc."");
	
?>